package com.wjw.rabbitdemo.controller;

import com.wjw.rabbitdemo.entity.OrderEntity;
import com.wjw.rabbitdemo.entity.RabbitReturnEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;

@RestController
public class testController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @RequestMapping("test")
    public String testSend(){
        for(int i=1;i<=10;i++){
            if(i%2==0){
                RabbitReturnEntity rabbitReturnEntity=new RabbitReturnEntity();
                rabbitReturnEntity.setId(i);
                rabbitReturnEntity.setCreateTime(new Date());
                rabbitReturnEntity.setContent("rabbitReturnEntity"+i);
                rabbitTemplate.convertAndSend("hello-java-ExchangeDemo","hello.java",rabbitReturnEntity);
            }else {
                OrderEntity orderEntity=new OrderEntity();
                orderEntity.setId(i);
                orderEntity.setOrderContent("orderEntity"+i);
                rabbitTemplate.convertAndSend("hello-java-ExchangeDemo","hello.java",orderEntity);
            }

        }
        return "ok";
    }
    @RequestMapping("test1")
    public String testSend1(){
        RabbitReturnEntity pojo=new RabbitReturnEntity(1, new Date(),"测试内容");
        rabbitTemplate.convertAndSend("hello-java-ExchangeDemo","hello.java",pojo);
        return "ok";
    }
}
